package com.example.administrator.nurse.model;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import java.util.List;

/**
 * Created by 林冠宏 on 2016/3/4.
 *
 */

public abstract class RecyclerViewCommonAdapter<T> extends RecyclerView.Adapter<RecyclerViewCommonAdapter.viewHolder> {

    private Context context;
    private List<T> list;
    public OnItemClickListener onItemClickListener;

    public RecyclerViewCommonAdapter(Context context,List<T> list){
        this.context = context;
        this.list    = list;
    }

    public interface OnItemClickListener{
        void onItemClick(View view,int position);
        void onItemLongClick(View view,int position);
    }

    public void setOnItemClickListener(OnItemClickListener clickListener){
        this.onItemClickListener=clickListener;
    }

    protected abstract int  getLayoutId();
    protected abstract void bindView(CommonViewHolder holder, int position);

    @Override
    public viewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new viewHolder(LayoutInflater.from(context).inflate(getLayoutId(),parent,false));
    }

    @Override
    public void onBindViewHolder(viewHolder holder, int position) {
        bindView(holder.getViewHolder(),position);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class viewHolder extends RecyclerView.ViewHolder{

        private CommonViewHolder commonViewHolder;

        public viewHolder(View itemView) {
            super(itemView);
            commonViewHolder = CommonViewHolder.getViewHolder(itemView);
        }

        public CommonViewHolder getViewHolder() {
            return commonViewHolder;
        }

    }

}
